<template>
	<view class="route">
		<view class="imgcont">
			<image class="img" :src="image" mode="widthFix"></image>
		</view>
		<view class="inner">
			<view class="inner-item" v-for="(item,index) in info" :key="index" @click="handleBuy(item)">
				<view class="item-left">
					{{item.name}}
				</view>
				<view class="item-right">
					<view class="price">
						￥{{item.price}}
					</view>
					<view class="yuan">
						{{item.originalprice}}
					</view>
				</view>
			</view>

		</view>
		<u-modal :show="showMa" @confirm="showMa=false">
			<view class="slot-content">
				<view class="imgcont">
					<image :src="ma" mode="widthFix" class="img"></image>
				</view>
				<view class="text">
					如果你想继续使用该平台，请联系客服
				</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showMa: false,
				id: '',
				activeId: '',
				info: '',
				image: '',
				ma: ''
			};
		},
		onLoad(options) {
			if (options.id) {
				this.id = Number(options.id)
				this.getInfo()
				this.getImg()
				this.getma()
			}
		},
		methods: {
			getInfo() {
				this.$req.post('/web/vippackagelist', {
					id: this.id,
					uid: uni.getStorageSync('uid')
				}).then((res) => {
					let info = res.data.data
					this.info = info
				})
			},
			getImg() {
				this.$req.post('/web/vippackageimage', {
					id: this.id,

				}).then((res) => {
					this.image = res.data.data
				})
			},
			getma() {
				this.$req.post('/shanghu/kefuimage', {}).then((res) => {
					this.ma = res.data.data
				})
			},
			handleBuy(row) {
				const info = wx.getSystemInfoSync()
				if (info.system.indexOf('Android') > -1) {
					let req = {
						uid: uni.getStorageSync('uid'),
						vippackageid: row.id
					}
					uni.showLoading({

					})
					this.$req.post('/shanghu/wechatpay', req).then((res) => {
						uni.hideLoading()
						let data = res.data
						if (data.code === 0) {
							let paydata = data.data
							this.pay(paydata)
						} else {
							wx.showToast({
								mask: true,
								icon: 'none',
								title: data,
								msg
							})
						}
					})
				} else {
					this.showMa = true
				}
			},
			pay(paydata) {
				wx.requestPayment({
					nonceStr: paydata.nonceStr, // 随机字符串
					package: paydata.package, // 固定值
					signType: paydata.signType, // 统一下单订单号 
					timeStamp: paydata.timeStamp, // 时间戳（单位：秒）
					paySign: paydata.sign, // 签名，这里用的 MD5/RSA 签名
					success(res) {
						uni.navigateBack()
					},
					fail(e) {
						wx.showToast({
							mask: true,
							icon: '支付失败',
							title: data,
							msg
						})

						console.log(e, 8888)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.route {
		padding-bottom: 40rpx;

		.slot-content {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			.imgcont {

				width: 400rpx;


				.img {
					display: block;
					width: 100%;
					height: 100%;
				}
			}

			.text {
				margin-top: 20rpx;
				font-size: 26rpx;
			}
		}

		.imgcont {
			width: 100%;
			// height: 760rpx;

			.img {
				display: block;
				width: 100%;
				height: 100%;
			}
		}

		.inner {
			margin-top: 40rpx;
			padding: 0 30rpx;

			.inner-item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				height: 120rpx;
				padding: 0 24rpx;
				border: 1px solid #edf0f2;
				border-radius: 12rpx;
				margin-bottom: 30rpx;

				.item-left {}

				.item-right {
					display: flex;
					align-items: center;

					.price {
						font-size: 32rpx;
						color: #fa3534;
						font-weight: 500;
					}

					.yuan {
						color: #999;
						padding-left: 20rpx;
						text-decoration: line-through;
					}
				}
			}
		}
	}
</style>